package com.smcdd.cdb.dbo.cdb_dbo.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;

/**
 * 作者：Administrator on 2017/6/20 14:20
 * 邮箱：zhanghuaiha@gmail.com
 */

public class HistoryTcAdapter extends RecyclerView.Adapter<HistoryTcAdapter.ViewHolder> {
    private Context mContext;
    private OnItemClickListenter onItemClickListenter;
    private String[] str;

    public HistoryTcAdapter(Context context, String[] array){
        mContext = context;
        str = array;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_top,parent,false);
        return new ViewHolder(view);

    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.item_string.setText(str[position]);
        switch (position) {
            case 0:
                holder.item_string.setBackgroundResource(R.color.hint_one);
                holder.item_string.setSelected(true);
                break;
            case 1:
                holder.item_string.setSelected(false);
                break;
            case 2:
                holder.item_string.setSelected(false);
                break;
            case 3:
                holder.item_string.setSelected(false);
                break;
            case 4:
                holder.item_string.setSelected(false);
                break;
            case 5:
                holder.item_string.setSelected(false);
                break;
            case 6:
                holder.item_string.setSelected(false);
                break;
            case 7:
                holder.item_string.setSelected(false);
                break;
            case 8:
                holder.item_string.setSelected(false);
                break;
            case 9:
                holder.item_string.setSelected(false);
                break;


        }
        holder.itemView.setTag(position);
        holder.itemView.setOnClickListener(v -> {
            onItemClickListenter.itemClickListenter(str[position],position,holder.item_string);
        });
    }

    @Override
    public int getItemCount() {
        return str == null? 0 : str.length;
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        TextView item_string;
        public ViewHolder(View itemView) {
            super(itemView);
            item_string = (TextView) itemView.findViewById(R.id.item_string);
        }
    }


    public interface OnItemClickListenter {
        void itemClickListenter(String scan, int position, TextView view);
    }

    public void setItemClickListenter(OnItemClickListenter itemClickListenter) {
        onItemClickListenter = itemClickListenter;
    }

}
